home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / src / signals.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-11  |  5.2 KB  |  231 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: signals.c,v 5.8 1993/04/12 03:04:58 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.8 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: signals.c,v $
  17.  * Revision 5.8  1993/04/12  03:04:58  syd
  18.  * The USR2 signal lost messages on some OS:es and did an unnecessary resync
  19.  * on others.
  20.  * From: Jan Djarv <Jan.Djarv@sa.erisoft.se>
  21.  *
  22.  * Revision 5.7  1993/01/20  03:43:37  syd
  23.  * Some systems dont have SIGBUS, make it optional
  24.  *
  25.  * Revision 5.6  1992/12/11  02:39:53  syd
  26.  * A try at making USR? not loose mailbox
  27.  *
  28.  * Revision 5.5  1992/12/07  02:41:21  syd
  29.  * This implements the use of SIGUSR1 and SIGUSR2 as discussed on the
  30.  * mailing list recently, and adds them to the documentation.
  31.  * From: scs@lokkur.dexter.mi.us (Steve Simmons)
  32.  *
  33.  * Revision 5.4  1992/11/26  00:46:13  syd
  34.  * changes to first change screen back (Raw off) and then issue final
  35.  * error message.
  36.  * From: Syd
  37.  *
  38.  * Revision 5.3  1992/10/27  01:43:40  syd
  39.  * Move posix_signal to lib directory
  40.  * From: tom@osf.org
  41.  *
  42.  * Revision 5.2  1992/10/25  02:01:58  syd
  43.  * Here are the patches to support POSIX sigaction().
  44.  * From: tom@osf.org
  45.  *
  46.  * Revision 5.1  1992/10/03  22:58:40  syd
  47.  * Initial checkin as of 2.4 Release at PL0
  48.  *
  49.  *
  50.  ******************************************************************************/
  51.  
  52. /** This set of routines traps various signals and informs the
  53.     user of the error, leaving the program in a nice, graceful
  54.     manner.
  55.  
  56. **/
  57.  
  58. #include "headers.h"
  59. #include "s_elm.h"
  60.  
  61. extern int pipe_abort;        /* set to TRUE if receive SIGPIPE */
  62.  
  63. SIGHAND_TYPE
  64. quit_signal(sig)
  65. {
  66.     dprint(1, (debugfile, "\n\n** Received SIGQUIT **\n\n\n\n"));
  67.     leave(0);
  68. }
  69.  
  70. SIGHAND_TYPE
  71. hup_signal(sig)
  72. {
  73.     dprint(1, (debugfile, "\n\n** Received SIGHUP **\n\n\n\n"));
  74.     leave(0);
  75. }
  76.  
  77. SIGHAND_TYPE
  78. term_signal(sig) 
  79. {
  80.     dprint(1, (debugfile, "\n\n** Received SIGTERM **\n\n\n\n"));
  81.     leave(0);
  82. }
  83.  
  84. SIGHAND_TYPE
  85. ill_signal(sig)
  86. {
  87.     MoveCursor(LINES,0);
  88.     Raw(OFF);
  89.     dprint(1, (debugfile, "\n\n** Received SIGILL **\n\n\n\n"));
  90.     printf(catgets(elm_msg_cat, ElmSet, ElmIllegalInstructionSignal,
  91.         "\n\nIllegal Instruction signal!\n\n"));
  92.     emergency_exit();
  93. }
  94.  
  95. SIGHAND_TYPE
  96. fpe_signal(sig)  
  97. {
  98.     MoveCursor(LINES,0);
  99.     Raw(OFF);
  100.     dprint(1, (debugfile, "\n\n** Received SIGFPE **\n\n\n\n"));
  101.     printf(catgets(elm_msg_cat, ElmSet, ElmFloatingPointSignal,
  102.         "\n\nFloating Point Exception signal!\n\n"));
  103.     emergency_exit();
  104. }
  105.  
  106. #ifdef SIGBUS
  107. SIGHAND_TYPE
  108. bus_signal(sig)
  109. {
  110.     MoveCursor(LINES,0);
  111.     Raw(OFF);
  112.     dprint(1, (debugfile, "\n\n** Received SIGBUS **\n\n\n\n"));
  113.     printf(catgets(elm_msg_cat, ElmSet, ElmBusErrorSignal,
  114.         "\n\nBus Error signal!\n\n"));
  115.     emergency_exit();
  116. }
  117. #endif
  118.  
  119. SIGHAND_TYPE
  120. segv_signal(sig)
  121. {
  122.     MoveCursor(LINES,0);
  123.     Raw(OFF);
  124.     dprint(1, (debugfile,"\n\n** Received SIGSEGV **\n\n\n\n"));
  125.     printf(catgets(elm_msg_cat, ElmSet, ElmSegmentViolationSignal,
  126.         "\n\nSegment Violation signal!\n\n"));
  127.     emergency_exit();
  128. }
  129.  
  130. SIGHAND_TYPE
  131. alarm_signal(sig)
  132. {    
  133.     /** silently process alarm signal for timeouts... **/
  134. #ifdef    BSD
  135.     if (InGetPrompt)
  136.         longjmp(GetPromptBuf, 1);
  137. #else
  138.     signal(SIGALRM, alarm_signal);
  139. #endif
  140. }
  141.  
  142. SIGHAND_TYPE
  143. pipe_signal(sig)
  144. {
  145.     /** silently process pipe signal... **/
  146.     dprint(2, (debugfile, "*** received SIGPIPE ***\n\n"));
  147.     
  148.     pipe_abort = TRUE;    /* internal signal ... wheeee!  */
  149.  
  150.     signal(SIGPIPE, pipe_signal);
  151. }
  152.  
  153. #ifdef SIGTSTP
  154. int was_in_raw_state;
  155.  
  156. SIGHAND_TYPE
  157. sig_user_stop(sig)
  158. {
  159.     dprint(1, (debugfile,"\n\n** Received SIGTSTP **\n\n\n\n", sig));
  160.     /* This is called when the user presses a ^Z to stop the
  161.        process within BSD 
  162.     */
  163. #ifdef    SIGTSTP
  164.     signal(SIGTSTP, SIG_DFL);
  165. #endif
  166.  
  167.     was_in_raw_state = RawState();
  168.     Raw(OFF);    /* turn it off regardless */
  169.  
  170.     printf(catgets(elm_msg_cat, ElmSet, ElmStoppedUseFGToReturn,
  171.         "\n\nStopped.  Use \"fg\" to return to ELM\n\n"));
  172.  
  173.     kill(0, SIGSTOP);
  174. }
  175.  
  176. SIGHAND_TYPE
  177. sig_return_from_user_stop(sig)
  178. {
  179.     /** this is called when returning from a ^Z stop **/
  180.     dprint(1, (debugfile,"\n\n** Received SIGCONT **\n\n\n\n", sig));
  181.  
  182. #ifndef    BSD
  183.     signal(SIGCONT, sig_return_from_user_stop);
  184. #endif
  185.     signal(SIGTSTP, sig_user_stop);
  186.  
  187.     printf(catgets(elm_msg_cat, ElmSet, ElmBackInElmRedraw,
  188.      "\nBack in ELM. (You might need to explicitly request a redraw.)\n\n"));
  189.  
  190.     if (was_in_raw_state)
  191.       Raw(ON);
  192.  
  193. #ifdef    BSD
  194.     if (InGetPrompt)
  195.         longjmp(GetPromptBuf, 1);
  196. #endif
  197. }
  198. #endif
  199.  
  200. #ifdef SIGWINCH
  201. SIGHAND_TYPE
  202. winch_signal(sig)
  203. {
  204. #ifndef    BSD
  205.     signal(SIGWINCH, winch_signal);
  206. #endif
  207.     resize_screen = 1;
  208. }
  209. #endif
  210.  
  211. SIGHAND_TYPE
  212. usr1_signal(sig)
  213. {
  214.     dprint(1, (debugfile, "\n\n** Received SIGUSR1 **\n\n\n\n"));
  215.     question_me = FALSE;
  216.     while ( leave_mbox(TRUE, FALSE, TRUE) == -1)
  217.         newmbox(cur_folder, TRUE);
  218.  
  219.     leave(0);
  220. }
  221.  
  222. SIGHAND_TYPE
  223. usr2_signal(sig)
  224. {
  225.     dprint(1, (debugfile, "\n\n** Received SIGUSR2 **\n\n\n\n"));
  226.     while ( leave_mbox(FALSE, TRUE, FALSE) == -1)
  227.         newmbox(cur_folder, TRUE);
  228.  
  229.     leave(0);
  230. }
  231.